package com.zheng.russiaRec.controller 
{
	
	import com.zheng.russiaRec.model.P_Checkerboard;
	import com.zheng.russiaRec.staticData.EventData;
	
	import flash.ui.Keyboard;
	
	import org.puremvc.as3.interfaces.INotification;
	
	/**
	 * @describe  	移动积木
	 * @author  	Mr.zheng
	 * @website 	http://blog.sina.com.cn/zihua2007
	 * @time		... 
	 */
	public class C_MoveGroup extends C_BaseCommand
	{	
		override public function execute(notification:INotification):void 
		{
			var userOP:int = notification.getBody().userOP;
			var temp:Array=[];
			var moveStatus:int;
			var dx:int;
			var dy:int;
			switch (userOP) 
			{
				case Keyboard.DOWN:
					dx=0;dy=1;
					break;
				case Keyboard.LEFT:
					dx=-1;dy=0;
					break;
				case Keyboard.RIGHT:
					dx=1;dy=0;
					break;
				case Keyboard.NUMPAD_0:
					var tempDy:int=p_cb.getMinDis();
					dx = 0; 
					if(tempDy>0){
						dy=tempDy-1;
					}else{
						dy=0;
					}
					break;
			}
			if(userOP==Keyboard.DOWN||userOP==Keyboard.LEFT||userOP==Keyboard.RIGHT||userOP==Keyboard.NUMPAD_0){
				temp=p_cb.setLiveToGroup(dx, dy);
				moveStatus=p_cb.getTargetStatus(temp,userOP);
				p_cb.dealMoveStatus(temp,moveStatus);
				//能够正常到达目标rec
				if(moveStatus==P_Checkerboard.CAN_MOVE_TO){
					sendNotification(EventData.P_GROUP_UPDATE);
					p_cb.setLgOffset(dx,dy);
				}
			}
		}
		
	}
	
}